<form class="layui-form " style="margin-top: 20px">
    <div class="layui-form-item">
        <div class="layui-input-block" hidden>
            <input id="expaid" name="expaid" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">科目</label>
        <div class="layui-input-inline">
            <select id="questionSubject" name="subjid"  >
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">阶段</label>
        <div class="layui-input-inline">
            <select id="questionStage" name="stage"  >
            </select>
        </div>
    </div>
    <div  id="hasAdd">

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">考题类型</label>
        <div class="layui-input-inline">
            <select id="questionType" name="typeid"  >
            </select>
        </div>
        <label class="layui-form-label">数量</label>
        <div class="layui-input-inline">
            <input type="number" id="questionNum" name="num" class="layui-input" >
        </div>
        <label class="layui-form-label">总分</label>
        <div class="layui-input-inline">
            <input type="number" id="countScore" name="countScore" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
            <button class="layui-btn layui-btn-primary" lay-submit lay-filter="continueBtn">添加继续</button>
            <button class="layui-btn layui-btn-primary" lay-submit lay-filter="saveBtn">保存</button>
        </div>
    </div>
</form>
<script>
    typeIdOff=[];
    stageOff=[];
    paperQuestionParam=[];
    layui.use(['form', 'config', 'admin','layer'], function () {
        var admin=layui.admin;
        var form=layui.form;
        var layer=layui.layer;
        var tempData = admin.getTempData("paper_data");
        $("#expaid").val(tempData.expaid);

        //获取科目类型
        admin.req("api-exam/questionSubject/findAll?status=1",{},function (res) {
            var data=res.data;
            for (let i = 0; i < data.length; i++) {
                $("#questionSubject").append('<option value="'+data[i].subjid+'">'+data[i].sjname+'</option>')
            }
        },"get");
        //获取考题阶段
        admin.req("api-exam/question/getStage",{},function (data) {
            for (let i = 0; i < data.length; i++) {
                $("#questionStage").append('<option value="'+data[i]+'">'+data[i]+'</option>')
            }
        },"get");
        //获取考题类型
        admin.req("api-exam/questionType/findAll",{},function (res) {
            var data=res.data;
            for (let i = 0; i < data.length; i++) {
                $("#questionType").append('<option value="'+data[i].typeid+'">'+data[i].tpname+'</option>')
            }
        },"get");
        form.render();

        //继续添加
        form.on("submit(continueBtn)",function (data) {
            for (let i = 0; i <typeIdOff.length; i++) {
                if(typeIdOff[i]==data.field.typeid&&stageOff[i]==data.field.stage){
                    layer.msg("不能重复添加");
                    return false;
                }
            }
            saveSuccess(data,form)
            paperQuestionParam.push(data.field);
            return false;
        });
        //保存
        form.on("submit(saveBtn)",function () {
            let param = JSON.stringify(paperQuestionParam);
            console.log(param,12138);
            admin.req("api-exam/examPaper/addPaperQue",param,function (res) {
                layer.msg(res.msg);

            },"POST");
            return false;
        })
    });
    function saveSuccess(data,form) {
        var typeName = $("#questionType option[value='"+data.field.typeid+"']").html();
        $("#hasAdd").append('<div class="layui-form-item layui-bg-gray" >' +
            '       <label class="layui-form-label">阶段</label>\n' +
            '        <div class="layui-input-inline">\n' +
            '            <input type="text" value="'+data.field.stage+'" class="layui-input layui-bg-gray" readonly >'+
            '        </div>\n' +
            '       <label class="layui-form-label">考题类型</label>\n' +
            '        <div class="layui-input-inline">\n' +
            '            <input type="text" value="'+typeName+'" class="layui-input layui-bg-gray" readonly >'+
            '        </div>\n' +
            '        <label class="layui-form-label">数量</label>\n' +
            '        <div class="layui-input-inline">\n' +
            '            <input type="text" value="'+data.field.num+'" class="layui-input layui-bg-gray" readonly>' +
            '        </div>' +
            '        <label class="layui-form-label">总分</label>\n' +
            '        <div class="layui-input-inline">\n' +
            '            <input type="text" value="'+data.field.countScore+'" class="layui-input layui-bg-gray" readonly>' +
            '        </div>' +
            '</div>'
        );
        typeIdOff.push(data.field.typeid);
        stageOff.push(data.field.stage);
        form.render();
        $("#questionNum").val('');
        $("#countScore").val('');
    }
</script>